From ae5a8b8de324b145ab066990f5aeba583c7a49c4 Mon Sep 17 00:00:00 2001 From: Jake Kerr Date: Sun, 5 Oct 2014 16:13:43 +0900 Subject: [PATCH] Let the help command work consistently everywhere This adds a dummy help command so that it's usage can be documented with docopt! Also adds help flags to all of the subcommands that were missing them. Without that `cargo help sub-command` shows Invalid Argument before the usage text. --- src/bin/cargo.rs | 1 + src/bin/config_for_key.rs | 7 ++++++- src/bin/config_list.rs | 7 ++++++- src/bin/git_checkout.rs | 1 + src/bin/help.rs | 22 ++++++++++++++++++++++ src/bin/locate_project.rs | 1 + src/bin/read_manifest.rs | 3 ++- src/bin/verify_project.rs | 1 + 8 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/bin/help.rs diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 09c2ec207..4f52d482d 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -58,6 +58,7 @@ macro_rules! each_subcommand( ($macro:ident) => ({ $macro!(fetch) $macro!(generate_lockfile) $macro!(git_checkout) + $macro!(help) $macro!(locate_project) $macro!(login) $macro!(new) diff --git a/src/bin/config_for_key.rs b/src/bin/config_for_key.rs index 2b3614787..f73f5bd6d 100644 --- a/src/bin/config_for_key.rs +++ b/src/bin/config_for_key.rs @@ -11,7 +11,12 @@ struct ConfigOut { } docopt!(ConfigForKeyFlags, " -Usage: cargo config-for-key --human --key= +Usage: + cargo config-for-key --human --key= + cargo config-for-key -h | --help + +Options: + -h, --help Print this message ") pub fn execute(args: ConfigForKeyFlags, diff --git a/src/bin/config_list.rs b/src/bin/config_list.rs index 2fd50b7f4..eb4254ad5 100644 --- a/src/bin/config_list.rs +++ b/src/bin/config_list.rs @@ -11,7 +11,12 @@ struct ConfigOut { } docopt!(ConfigListFlags, " -Usage: cargo config-list --human +Usage: + cargo config-list --human + cargo config-list -h | --help + +Options: + -h, --help Print this message ") pub fn execute(args: ConfigListFlags, diff --git a/src/bin/git_checkout.rs b/src/bin/git_checkout.rs index 402998494..703463711 100644 --- a/src/bin/git_checkout.rs +++ b/src/bin/git_checkout.rs @@ -8,6 +8,7 @@ use cargo::util::{Config, CliResult, CliError, human, ToUrl}; docopt!(Options, " Usage: cargo git-checkout [options] --url=URL --reference=REF + cargo git-checkout -h | --help Options: -h, --help Print this message diff --git a/src/bin/help.rs b/src/bin/help.rs new file mode 100644 index 000000000..8c9d9897d --- /dev/null +++ b/src/bin/help.rs @@ -0,0 +1,22 @@ +use docopt; + +use cargo::core::MultiShell; +use cargo::util::{CliResult, CliError}; + +docopt!(Options, " +Get some help with a cargo command. + +Usage: + cargo help + cargo help -h | --help + +Options: + -h, --help Print this message +") + +pub fn execute(_: Options, _: &mut MultiShell) -> CliResult> { + // This is a dummy command just so that `cargo help help` works. + // The actual delegation of help flag to subcommands is handled by the + // cargo command. + Err(CliError::new("Help command should not be executed directly.", 101)) +} diff --git a/src/bin/locate_project.rs b/src/bin/locate_project.rs index db1500525..812b8530e 100644 --- a/src/bin/locate_project.rs +++ b/src/bin/locate_project.rs @@ -10,6 +10,7 @@ Usage: Options: --manifest-path PATH Path to the manifest to build benchmarks for + -h, --help Print this message ", flag_manifest_path: Option) #[deriving(Encodable)] diff --git a/src/bin/read_manifest.rs b/src/bin/read_manifest.rs index cd7e84e5c..686c1a5b2 100644 --- a/src/bin/read_manifest.rs +++ b/src/bin/read_manifest.rs @@ -6,7 +6,8 @@ use cargo::sources::{PathSource}; docopt!(Options, " Usage: - cargo clean [options] --manifest-path=PATH + cargo read-manifest [options] --manifest-path=PATH + cargo read-manifest -h | --help Options: -h, --help Print this message diff --git a/src/bin/verify_project.rs b/src/bin/verify_project.rs index 21f8222f6..72358d48f 100644 --- a/src/bin/verify_project.rs +++ b/src/bin/verify_project.rs @@ -13,6 +13,7 @@ pub type Error = HashMap; docopt!(Flags, " Usage: cargo verify-project [options] --manifest-path PATH + cargo verify-project -h | --help Options: -h, --help Print this message -- 2.30.2